package 力扣日常刷题.木23一月.第17天317;

import 力扣日常刷题.TreeNode;

/**
 * @author 帅小伙
 * @date 2022/3/17
 * @description
 */
public class Demo90树的子结构 {

    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A != null && B != null) &&(
                (isSubStructure(A.right,B) ||
                        isSubStructure(A.left,B) ||
                        solution(A,B))
        );
    }

    public boolean solution(TreeNode A, TreeNode B) {
        if(B==null) return true;
        if(A == null || A.val != B.val) return  false;
        return solution(A.left,B.left) && solution(A.right,B.right);
    }
}
